package collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo4 {
    public static void main(String[] args) {
        //集合间的操作
        Collection c1=new ArrayList();
        c1.add("java");
        c1.add("php");
        c1.add("c++");
        System.out.println(c1);//[java, php, c++]

        //
        Collection c2=new ArrayList();
        c2.add("android");
        c2.add("ios");
        c2.add("java");
        System.out.println(c2);//[android, ios, java]

        //addAll()
        c1.addAll(c2);//将c2中的全部元素添加到c1中
        System.out.println("c1:"+c1);
        System.out.println("c2:"+c2);
        //containsAll()
        Collection c3=new ArrayList();
        c3.add(".net");
        c3.add("c++");
        c3.add("c");
        System.out.println("c3:"+c3);
        boolean b=c1.containsAll(c3);
        //判断c1中是否包含c3中所有元素
        System.out.println(b);

        //retainAll() 取并交集
        /*c1.retainAll(c3);//：c1中仅保留与c3中相同的元素，c3不变
        System.out.println("c1:"+c1);//[c++]
        System.out.println("c3:"+c3);//不变*/
        //removeAll() 删除c1中与c3中相同的元素
        c1.removeAll(c3);//删除交集：将c1中与c3中相同的元素删除
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);
    }
}
